package com.winit.schedule.core.repository;

import java.util.List;

import com.winit.schedule.core.model.JobID;
import com.winit.schedule.core.model.TaskID;
import com.winit.schedule.core.repository.constants.TaskStatus;
import com.winit.schedule.core.repository.entity.JobEntity;
import com.winit.schedule.core.repository.entity.TaskEntity;
import com.winit.schedule.core.repository.query.TaskQuery;

public interface TaskRepository {

    TaskEntity saveTaskEntity(TaskEntity taskEntity);

    List<TaskEntity> saveTaskEntity(List<TaskEntity> taskEntitys);

    void updateTaskInterfaceType(List<TaskEntity> taskEntitys);

    TaskEntity updateTaskStatus(String taskId, TaskStatus status);

    TaskEntity getTaskEntityById(String taskId);

    void removeTaskEntity(TaskID taskId);

    List<TaskEntity> findTaskEntity(TaskQuery query);

    /**
     * 更新所有关联jobId的task的状态
     * 
     * @param jobId
     * @param status
     */
    void updateTaskStatus(JobID jobId, TaskStatus status);

    /**
     * 查询所有已停止任务的ID
     * 
     * @return
     */
    List<TaskID> queryAllStopTaskIDs();

    /**
     * 查询所有未关联job的任务
     * 
     * @return
     */
    List<TaskEntity> queryTasksNotRelatedJob();

    List<TaskEntity> queryTasksRelatedJob(JobID jobId);

    /**
     * task关联job
     * 
     * @param jobId
     * @param isDelete
     */
    void saveJobIdForTask(JobEntity job, List<String> taskIds);

    /**
     * task取消关联job
     * 
     * @param jobId
     * @param isDelete
     */
    void delJobIdForTask(JobID jobId);

    /**
     * 根据jobID查询所有关联的taskID
     * 
     * @param jobId
     * @return
     */
    List<String> queryAllTaskIDByJobId(JobID jobId);

    long queryUnfinishedTaskNumber(String jobId);

}
